// app/service/user.js
'use strict';

const Service = require('egg').Service;

class UsersService extends Service {
  // 查所有的  定义方法
    async findAll(ctx) {
        //数据库查询表的语法
        const user = await this.app.mysql.get('db1').select('users');
        return {user};
    }
    async find(uid) {
      // 假如 我们拿到用户 id 从数据库获取用户详细信息
      const user = await this.app.mysql.get('db1').get('users', { id: uid });
      return { user };
    }
    async create(params){
      const date = new Date() 
      const cfg = {
        name:params.name,
        age:params.age,
        create_up:date,
        update_up:date
      }
      const result =await this.app.mysql.get('db1').insert('users',cfg)
      return {result}
    }
    async delete(num) {
        
      const result = await this.app.mysql.get('db3').delete('wakuang', { id:num })
      return { result }
  }
}

module.exports = UsersService;